<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id
 * @property int $uid 用户id
 * @property string $phone 手机号
 * @property int $type 类型(1注册,2修改密码)
 * @property int $operator
 * @property string $status
 * @property int $ctime 发送时间
 * @property string $content 短信发送内容
 */
class NoteSendRecord extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'tb_note_send_record';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'type' => 'integer', 'operator' => 'integer', 'ctime' => 'integer'];

    public function saveNote($uid, $phone, $code, $type): int
    {
        $data = [
            "uid" => $type == 2 ? 0 : $uid,
            "phone" => $phone,
            "content" => $code,
            "type" => $type,
            "ctime" => time(),
            "status" => "sending"
        ];

        return $this->query()->insertGetId($data);
    }
}
